package callback;

import java.util.ArrayList;
import java.util.List;

public class WeatherStation {
    private float temperature;
    private float humidity;
    private List<WeatherCallback> callbacks = new ArrayList<>();


    public void registerCallback(WeatherCallback callback) {
        callbacks.add(callback);
    }

    public void removeCallback(WeatherCallback callback) {
        callbacks.remove(callback);
    }

    public void setMeasurements(float temperature, float humidity) {
        this.temperature = temperature;
        this.humidity = humidity;
        notifyCallbacks();
    }

    private void notifyCallbacks() {
        for (WeatherCallback callback : callbacks) {
            callback.onWeatherChanged(temperature, humidity);
        }
    }
}
